package com.bangdao.app.jetpacktest.architecture.mvp.presenter;

import com.bangdao.app.jetpacktest.architecture.mvp.model.Callback;
import com.bangdao.app.jetpacktest.architecture.mvp.model.User;
import com.bangdao.app.jetpacktest.architecture.mvp.model.UserRepository;
import com.bangdao.app.jetpacktest.architecture.mvp.view.IUserView;

import java.util.List;

/**
 * @ProjectName: JetpackTest
 * @ClassName: UserPresenter
 * @Description: java类作用描述
 * @Author: luhui
 * @Email: hui.lu@bangdao-tech.com
 * @CreateDate: 2022/6/19 22:28
 * @UpdateUser: luhui
 * @UpdateDate: 2022/6/19 22:28
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class UserPresenter implements IUserPresenter{

    //View
    private IUserView userView;
    //Model
    private UserRepository userRepository;

    public UserPresenter(IUserView userView) {
        this.userView = userView;
        this.userRepository = UserRepository.getUserRepository();
    }

    /**
     * 获取用户信息
     */
    @Override
    public void getUserInfo() {
        userView.showProgressBar(true);

        userRepository.getUserRepository().getUsersFromServer(new Callback<List<User>>() {
            @Override
            public void onSuccess(List<User> users) {
                userView.showProgressBar(false);
                userView.showUserList(users);
            }

            @Override
            public void onFailed(String msg) {
                userView.showProgressBar(false);
                userView.showUserList(null);
            }
        });
    }
}
